home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.02 Feb 90 / FuzzyBrush source / CenterWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-07  |  2.3 KB  |  100 lines  |  [TEXT/KAHL]

  1.  
  2. /*
  3.  
  4.     NAME
  5.         CenterWindow - center a DLOG, ALRT, 
  6.         or WIND resource
  7.  
  8.     DESCRIPTION
  9.         Reads resource into memory and modifies
  10.         bounds rect so it is somewhat centered 
  11.         on the screen.
  12.  
  13.  
  14.     INPUT PARAMETERS
  15.         Type...............................ResType
  16.             Resource Type 'DLOG', 'ALRT', or 'WIND'.
  17.  
  18.         ID...................................short
  19.             Resource number for DLOG, ALRT, or WIND.
  20.  
  21.  
  22.     OUTPUT PARAMETERS
  23.         none
  24.  
  25.  
  26.     HISTORY
  27.         Dana - Jun 21, 1988   9:33 AM (new)
  28.         Linda - July 10, 1989            
  29.  
  30.  
  31.     COPYRIGHT © 1989 Silicon Beach Software, Inc.
  32.     Permission is hereby granted to the purchaser
  33.     to use this source code for the limited
  34.     purpose of producing and distributing compiled
  35.     object files and applications.  The source
  36.     code is and shall remain the sole property of
  37.     Silicon Beach Software, Inc., and except as
  38.     expressly provided, purchaser obtains no
  39.     right, title or interest in the source code.
  40.     Distribution of the un-compiled or text
  41.     versions of this source code is prohibited.
  42.  
  43. */
  44.  
  45. #define     MBarHeight        ( *(short  *)0xBAA )
  46. #define        nil        0
  47.  
  48. CenterWindow( Type, ID )
  49.  
  50. ResType        Type;
  51. short        ID;
  52.         
  53. {
  54.  
  55.     DialogTHndl            windowHdl;
  56.     Rect                boundsRect;
  57.     short                screenHeight;
  58.     short                screenWidth;
  59.     short                boxHeight;
  60.     short                boxWidth;    
  61.     short                topMargin;
  62.     short                leftMargin;
  63.     GrafPtr                tempPort, savePort;
  64.     
  65.     windowHdl     = (DialogTHndl)GetResource( Type, ID );
  66.     
  67.     if( windowHdl != nil ) {
  68.         /* open a temporary port to */
  69.         /* get the size of the screen */
  70.         GetPort( &savePort );
  71.         tempPort = (GrafPtr)NewPtr( sizeof( GrafPort ) );
  72.         OpenPort( tempPort );
  73.         screenWidth = tempPort->portRect.right - 
  74.             tempPort->portRect.left;
  75.         screenHeight = tempPort->portRect.bottom -
  76.             tempPort->portRect.top - MBarHeight;
  77.         ClosePort( tempPort );
  78.         DisposPtr( (Ptr)tempPort );
  79.         SetPort( savePort );
  80.  
  81.         /* get size of dialog window */
  82.         boundsRect = (*windowHdl)->boundsRect;
  83.         boxHeight = boundsRect.bottom - boundsRect.top;
  84.         boxWidth = boundsRect.right  - boundsRect.left;
  85.  
  86.         /* compute position for the dialog */
  87.         topMargin = (screenHeight-boxHeight)/4;
  88.         leftMargin = (screenWidth-boxWidth)/2;
  89.         
  90.         boundsRect.top = MBarHeight + topMargin;
  91.         boundsRect.left = leftMargin;
  92.         boundsRect.bottom = boundsRect.top  + boxHeight;
  93.         boundsRect.right = boundsRect.left + boxWidth;
  94.         
  95.         (*windowHdl)->boundsRect = boundsRect;
  96.  
  97.         }/* if( got the resource ) */
  98.     }/*CenterWindow*/
  99.  
  100.